<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('代码生成列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">


        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="javascript:batchGenCode()" shiro:hasPermission="tool:gen:code">
                <i class="fa fa-download"></i> 批量生成
            </a>
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>


        </div>

        <div class="col-sm-12 select-table table-striped">
            <form action="" method="post" id="genForm">

                <table id="bootstrap-table" data-mobile-responsive="true"></table>
                <div class="row">
                    <div class="col-sm-offset-5 col-sm-10">
                        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "columnInfoController";
    var tableName = '[[${tableName}]]';

    $(function() {
        var options = {
            url: prefix + "/list?tableName="+tableName,
            showExport: true,
            columns: [{
                checkbox: true
            },
//                {
//                    title: "序号",
//                    formatter: function (value, row, index) {
//                        return $.table.serialNumber(index);
//                    }
//                },
                {
                    field: 'columnName',
                    title: '列名',
                    width: '20%',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return"<input name='columnName["+index+"]' value='"+value+"'>";
                    }
                },
                {
                    field: 'dataType',
                    title: '类型',
                    width: '20%',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return"<input name='dataType["+index+"]' value='"+value+"'>";
                    }
                },
                {
                    field: 'columnComment',
                    title: '说明',
                    width: '20%',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return"<input name='columnComment["+index+"]' value='"+value+"'>";
                    }
                },
                {
                    field: 'characterMaxinumLength',
                    title: '长度',
                    width: '20%',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return"<input name='characterMaxinumLength["+index+"]' value='"+value+"'>";
                    }
                },
                {
                    field: 'isNullable',
                    title: '必填',
                    width: '20%',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return"<input name='isNullable["+index+"]' value='"+value+"'>";
                    }
                },
                {
                    field: 'isNullable',
                    title: '表单类型',
                    width: '20%',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var html="<select >";
                        html+="<option value='text' class='form-control'>文本框</option>"
                        html+="<option value='password' class='form-control'>密码框</option>"
                        html+="<option value='select' class='form-control'>下拉框</option>"
                        html+="<option value='textarea' class='form-control'>文本域</option>"
                        html+="<option value='date' class='form-control'>日期框</option>"
                        html+="</select>"
                        return html;
                    }
                },

                {
                    title: '操作',
                    width: '20%',
                    align: 'center'
                }]
        };
        $.table.init(options);
    });

    // 生成代码
    function genCode(tableName) {

        alert(JSON.stringify($("#genForm").serializeArray()))
//        $.modal.confirm("确定要生成" + tableName + "表代码吗？", function() {
//            location.href = prefix + "/genCode/" + tableName;
//            layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
//        })
    }
    function toTableInfo(tableName) {
        location.href = "/columnInfoController/tableInfo/" + tableName;
    }

    //批量生成代码
    function batchGenCode() {
        alert(JSON.stringify($("#genForm").serializeArray()))

//        var rows = $.table.selectColumns("tableName");
//        if (rows.length == 0) {
//            $.modal.alertWarning("请选择要生成的数据");
//            return;
//        }
//        $.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function() {
//            location.href = prefix + "/batchGenCode?tables=" + rows;
//            layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
//        });
    }
</script>
</body>
</html>